﻿using System;
using System.Diagnostics.Contracts;

namespace Cloak.Mvvm.Navigation
{
	/// <summary>
	/// Associates a querystring value with a parameter specified during resolution of a view model
	/// </summary>
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	public sealed class ViewModelQueryStringParameterAttribute : Attribute
	{
		/// <summary>
		/// Initializes an instance of <see cref="ViewModelQueryStringParameterAttribute"/>
		/// </summary>
		/// <param name="queryStringKey">The querystring key which provides the parameter value</param>
		public ViewModelQueryStringParameterAttribute(string queryStringKey)
		{
			Contract.Requires(!String.IsNullOrEmpty(queryStringKey));

			QueryStringKey = queryStringKey;
		}

		/// <summary>
		/// Initializes an instance of <see cref="ViewModelQueryStringParameterAttribute"/>
		/// </summary>
		/// <param name="queryStringKey">The querystring key which provides the parameter value</param>
		/// <param name="valueType">The type of the parameter value</param>
		public ViewModelQueryStringParameterAttribute(string queryStringKey, Type valueType) : this(queryStringKey)
		{
			Contract.Requires(valueType != null);

			ValueType = valueType;
		}

		/// <summary>
		/// Gets the querystring key which provides the parameter value
		/// </summary>
		public string QueryStringKey { get; private set; }

		/// <summary>
		/// Gets the type of the parameter value
		/// </summary>
		public Type ValueType { get; private set; }

		/// <summary>
		/// Gets or sets the name of the parameter in the view model's constructor which is supplied by the querystring value
		/// </summary>
		public string ViewModelParameterName { get; set; }
	}
}